struct Cat {
    id: String,
    name: String,
    sn:String,
}
fn del_one(conn:rusqlite::Connection,id1:String) -> rusqlite::Result<()>{
    println!("=========");
    println!("{}",id1);
    let mut stmt = conn.prepare(
        "select * from result where SampleId>=?",
    )?;

    let cats = stmt.query_map(&[&id1], |row| {
        Ok(Cat {
            id: row.get(0)?,
            name: row.get(1)?,
            sn: row.get(2)?,
        })
    })?;
    let mut sn=String::new();
    for row in cats{
        let o=row.unwrap();
        println!("<id{},{}",o.sn,o.id);
        sn=o.sn;
        break;
    }
    println!("{}",sn);
    if sn=="" {
        return Ok(());
    }
    return Ok(());
    conn.execute(
            "delete  from result where SampleId=?",
           &[&id1]
        )?;
    // c.execute("delete  from result where SampleId='%s'" % id1)
    // c.execute("select * from result where SampleId>'%s'" % id1)
    let mut stmt = conn.prepare(
        "select * from result where SampleId>?",
    )?;

    let cats = stmt.query_map(&[&id1], |row| {
        Ok(Cat {
            id: row.get(0)?,
            name: row.get(1)?,
            sn: row.get(2)?,
        })
    })?;
    let mut sn1=sn.parse::<i32>().unwrap();
    for row in cats{
        let o=row.unwrap();
        let sn1_str=sn1.to_string();
        conn.execute(
            "update result set sampleNum=? where SampleId=?",
           &[&sn1_str,&id1]
        )?;
        sn1+=1;
    }
    return Ok(());
}

fn rename_one(conn:rusqlite::Connection,id1:String) -> rusqlite::Result<()> {//从一天开始到该时间
   
   let dbegin=day_begin(id1.clone());
   println!("{}->{}",id1,dbegin);
   conn.execute(
            "update  result set SampleName='' where SampleId<? and SampleId>?",
           &[&id1, &dbegin]
        )?;
   Ok(())
}
fn rename_all(conn:rusqlite::Connection,id1:String) -> rusqlite::Result<()>{//该时间之前
    conn.execute(
            "update result set sampleName=' '  where SampleId<?",
           &[&id1,]
        )?;
    Ok(())
}
fn db() -> rusqlite::Result<()> {
    let constr=String::from("data.sqlite");
    let conn = rusqlite::Connection::open(constr)?;
    //let r=rename_one(conn,String::from("2021-06-29 13:52"));
    let r=del_one(conn,String::from("2020-06-29 13:25"));
    println!("{:?}",r);
    // changeOne(conn,'2021-06-29 13:52',1/1.005,constr)
    Ok(())
}
fn day_begin(s:String) ->String {//'2016-12-23 14:59'    
    let tokens=s.split(" ");
    let mut r=String::new();
    for token in tokens{
        println!("{:?}",token );
        r.push_str(token);
        break;//first token
    }
    r.push_str(" 00:00");
    return r;   
} 
fn minute_j1(id1:String) ->String {
    let tokens=id1.split(" ");
    let mut a=Vec::new();
    for token in tokens{
        a.push(token);
    }
    let d=a[0];
    let t=a[1];
    println!("{},{}",d,t);
    let tokens=d.split("-");
    let mut a=Vec::new();
    for token in tokens{
        a.push(token);
    }
    let y=a[0];
    let mon=a[1];
    let d=a[2];
    println!("{},{},{}",y,mon,d);
    let tokens=t.split(":");
    let mut a=Vec::new();
    for token in tokens{
        a.push(token);
    }
    let h=a[0];
    let min=a[1];
    println!("{},{}",h,min);
    // let d=tokens.get(0);
    // (y,M,d)=d.split("-");
    // (h,m)=t.split(":");
    // d=datetime.datetime(int(y),int(M),int(d),int(h),int(m),0);
    // d2=d+datetime.timedelta(1/24/60);
    // print(d);
    // print(d2);
    return String::from("hello");
    // return "%04d-%02d-%02d %02d:%02d" % (d2.year,d2.month,d2.day,d2.hour,d2.minute)
}

pub fn main(){
   let s=String::from("2020-06-29 13:25");
   let s1=s.clone();
   let j1=minute_j1(s1);
   println!("{}->{}",s,j1);
   // db();
}
